﻿<?LassoScript
/*
This is an Open Source calendar based on the Jquery plugin Weekcalendar by Rob Monie with some additional Javascript by Jolle Carlestam. The server side is all Lasso on Knop written by Jolle Carlestam.

The file jina_weekStartStop.inc contains a custom tag used to extract start and stop dates fro ma given date. It's included into your solution if not already available.

*/

define_tag('weekstartstop',
	-namespace = 'jina_',
	-required = 'date', -copy);

	if(#date -> type != 'date');
		#date = date( #date, -format='%y-%m-%d');
	/if;

	if(#date -> type != 'date');
		fail(8020, 'submitted date not of date type');
	/if;

	local('dayofweek' = #date -> dayofweek);

	local('startdate'= ((#dayofweek != 1) ? date_subtract((#date), -day = (#dayofweek - 2))
		| date_subtract((#date),-day = 6)));

	local('stopdate' = date_add((#startdate),-day = 6));
	local('thedates' = array((#startdate -> format('%Q')), (#stopdate -> format('%Q'))));

	return(#thedates);
/define_tag;
	
?>